{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/StoreTruck/index')}">信息管理</a></li>
            <li class="layui-this">添加信息</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/StoreTruck/save')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">车型</label>
                        <div class="layui-input-block">
                            <select name="type">
                                <option value="">全部</option>
                                {foreach name="store_list" item="vo"}
                                {if $vo.pid == 3}
                                <option value="{$vo.id}">{$vo.name}</option>
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">品牌</label>
                        <div class="layui-input-block">
                            <select name="brand">
                                <option value="">全部</option>
                                {foreach name="store_list" item="vo"}
                                {if $vo.pid == 1}
                                <option value="{$vo.id}">{$vo.name}</option>
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">驱动</label>
                        <div class="layui-input-block">
                            <select name="drive">
                                <option value="">全部</option>
                                {foreach name="store_list" item="vo"}
                                {if $vo.pid == 4}
                                <option value="{$vo.id}">{$vo.name}</option>
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">马力</label>
                        <div class="layui-input-block">
                            <input type="text" name="soup" value="" required  lay-verify="required" placeholder="请输入马力" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">颜色</label>
                        <div class="layui-input-block">
                            <input type="text" name="color" value="" required  lay-verify="required" placeholder="请输入颜色" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">提车城市</label>
                        <div class="layui-input-inline">
                            <select name="site[]" lay-verify="required" id="site">
                                <option value="0">全国</option>
                                {foreach name="area_list" item="vo"}
                                {if $vo.parent_id == 0}
                                <option value="{$vo.id}">{$vo.name}</option>
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="site[]" lay-verify="required" id="site_son">
                                <option value="0">全省</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上牌地区</label>
                        <div class="layui-input-inline">
                            <select name="apply_site[]" lay-verify="required" id="apply">
                                <option value="0">全国</option>
                                {foreach name="area_list" item="vo"}
                                {if $vo.parent_id == 0}
                                <option value="{$vo.id}">{$vo.name}</option>
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <select name="apply_site[]" lay-verify="required" id="apply_son">
                                <option value="0">全省</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">燃料种类</label>
                        <div class="layui-input-block">
                            <input type="text" name="classify" value="" placeholder="请输入内容" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排放标准</label>
                        <div class="layui-input-block">
                            <input type="text" name="let" value="" placeholder="请输入内容" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">指导价(万)</label>
                        <div class="layui-input-block">
                            <input type="text" name="direct_price" value="" placeholder="请输入内容" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">价格(万)</label>
                        <div class="layui-input-block">
                            <input type="text" name="price" value="" placeholder="请输入价格" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">降价金额(万)</label>
                        <div class="layui-input-block">
                            <input type="text" name="low_price" value="" placeholder="(选填)请输入降价金额" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品详情</label>
                        <div class="layui-input-block">
                            <textarea name="content" placeholder="请输入商品详情" class="layui-textarea" id="content"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">参数配置</label>
                        <div class="layui-input-block">
                            <textarea name="peizhi" placeholder="请输入参数配置" class="layui-textarea" id="content"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图集</label>
                        <div class="layui-input-block">
                            <button type="button" id="upload-photo-btn" class="layui-btn">上传图集</button>
                            <div id="photo-container"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">查看次数</label>
                        <div class="layui-input-block">
                            <input type="text" name="reading" value="0" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">新车到店</label>
                        <div class="layui-input-block">
                            <input type="radio" name="new_truck" value="1" title="是">
                            <input type="radio" name="new_truck" value="0" title="否" checked="checked">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">置顶</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_top" value="1" title="置顶">
                            <input type="radio" name="is_top" value="0" title="未置顶" checked="checked">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">推荐</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_recommend" value="1" title="推荐">
                            <input type="radio" name="is_recommend" value="0" title="未推荐" checked="checked">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="已审核">
                            <input type="radio" name="status" value="0" title="未审核" checked="checked">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/kindeditor/kindeditor.config.js"></script>
<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>
{/block}
{block name="script"}
<script>
    $(document).ready(function () {
        var _kindEditor;
        KindEditor.ready(function(K) {
            _kindEditor = K.create('#content', KindEditorOptions);

            K('#upload-photo-btn').click(function () {
                var photo_list_item = '';
                _kindEditor.loadPlugin('multiimage', function() {
                    _kindEditor.plugin.multiImageDialog({
                        showRemote : false,
                        imageUrl : K('#photo').val(),
                        clickFn : function(data) {
                            $.each(data, function (index, item) {
                                photo_list_item += '<div class="photo-list"><input type="text" name="photo[]" value="' + item.url + '" class="layui-input layui-input-inline">';
                                photo_list_item += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>'
                            });
                            $('#photo-container').append(photo_list_item);
                            _kindEditor.hideDialog();
                        }
                    });
                });
            });
        });

        $('#photo-container').on('click', '.remove-photo-btn', function () {
            $(this).parent('.photo-list').remove();
        });

        form.on('select',function(data){
            //省2级联动
            $("select#site").next().find('dl').on('click','dd',function(){
                var parent_id = $(this).attr('lay-value');
                // console.log('开始');
                $.ajax({
                    url:'/index/area',
                    data:"id="+parent_id,
                    success:function(ell){
                        var i = 0;
                        $('#site_son').html('');
                        $('#site_son').append('<option value="0">全省</option>');
                        $('#site_son').next().find('dl').html('');
                        $('#site_son').next().find('dl').append('<dd lay-value="0" class="layui-this">全省</dd>');
                        $('#site_son').next().find('input').val('全省');
                        for(;i<ell.data.length;i++){
                            $('#site_son').append('<option value='+ell.data[i].id+'>'+ell.data[i].name+'</option>');
                            $('#site_son').next().find('dl').append('<dd lay-value='+ell.data[i].name+'>'+ell.data[i].name+'</dd>');
                        }
                        form.render('select');
                        // console.log('完毕');
                    }
                })
            });

            //省2级联动
            $("select#apply").next().find('dl').on('click','dd',function(){
                var parent_id = $(this).attr('lay-value');
                // console.log('开始');
                $.ajax({
                    url:'/index/area',
                    data:"id="+parent_id,
                    success:function(ell){
                        var i = 0;
                        $('#apply_son').html('');
                        $('#apply_son').append('<option value="0">全省</option>');
                        $('#apply_son').next().find('dl').html('');
                        $('#apply_son').next().find('dl').append('<dd lay-value="0" class="layui-this">全省</dd>');
                        $('#apply_son').next().find('input').val('全省');
                        for(;i<ell.data.length;i++){
                            $('#apply_son').append('<option value='+ell.data[i].id+'>'+ell.data[i].name+'</option>');
                            $('#apply_son').next().find('dl').append('<dd lay-value='+ell.data[i].name+'>'+ell.data[i].name+'</dd>');
                        }
                        form.render('select');
                        // console.log('完毕');
                    }
                })
            });

        });

    });
</script>
{/block}